<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/base_body_header.jsp" %>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="widget-box">
                <div class="widget-header">
                    <h4>幸运问答</h4>
                </div>

                <div class="widget-body">
                    <div class="widget-main no-padding">
                        <form:form class="form-horizontal" modelAttribute="sysUser"
                                   action="${GLOBAL.basePath}/Emily/add" method="post" id="userForm">
                            <input id="exp" name="exp" type="hidden" value="Emily">
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>请问怎么称呼您?
                                    </label>

                                    <div class="col-sm-5">
                                        <input name="name" id="name" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>


                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>手机号：
                                        <button type="button" class="btn btn-sm btn-info" onclick="myCourse()">
                                            我的课程
                                        </button>
                                        <span><font color="#ff7f50">
                                            (输入手机号查询课程)</font></span>
                                    </label>

                                    <div class="col-sm-5">
                                        <input id="phone" name="phone" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>您孩子的年龄?
                                    </label>

                                    <div class="col-sm-5">
                                        <input name="age" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>男孩还是女孩?
                                    </label>

                                    <div class="col-sm-5">
                                        <select class="form-control" name="sex">
                                            <option value="男">男孩</option>
                                            <option value="女">女孩</option>
                                        </select>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>
                                        您是从孩子多大开始了解家庭教育的?
                                    </label>

                                    <div class="col-sm-5">
                                        <input name="age1" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>
                                        您在家庭教育上一年的花费是多少?
                                    </label>

                                    <div class="col-sm-5">
                                        <input name="money" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>
                                        您在家庭教育方面曾经购买过哪些产品和服务?
                                    </label>

                                    <div class="col-sm-5">
                                        <input id="buyproduct" name="buyproduct" minlength="5" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>
                                        您个人比较推荐的是哪个产品或服务?
                                    </label>

                                    <div class="col-sm-5">
                                        <input id="recommendproject" name="recommendproject" minlength="5"
                                               maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>

                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <font color="red">*</font>
                                        目前在家庭教育方面，您最大的需求或者问题是什么？
                                    </label>

                                    <div class="col-sm-5">
                                        <input id=demand name="demand" minlength="5" maxlength="50"
                                               class="form-control required"/>
                                    </div>
                                </div>
                            </fieldset>


                            <div class="form-actions center">
                                <button type="submit" class="btn btn-sm btn-success" style="width: 300px" id="save_btn">
                                    提交
                                </button>
                            </div>
                        </form:form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="mask" class="img"></div>
</div>
<%@include file="../common/page_content_suf.jsp" %>
<%@include file="../common/script1.jsp" %>

<script>
    function showMask() {
        $("body").mLoading();
        $("#campusdsr").submit();
    }

    $(document).ready(function () {
        $("#userForm").validate({
            rules: {
                coursName: {
                    remote: {
                        type: "POST",
                        cache: false,
                        url: "${GLOBAL.basePath}/cours/checkName",
                        data: {
                            oldName: function () {
                                return "${sysRole.name}";
                            }
                        }
                    }
                },

                courseNumber: {
                    required: true,
                    range: [0, $("#count").val()]
                },
                phone: {
                    required: true,
                    isMobile: true
                },
                buyproduct: {
                    required: true,
                    minlength: 5
                },

                recommendproject: {
                    required: true,
                    minlength: 5
                },

                demand: {
                    required: true,
                    minlength: 5
                }
            },
            messages: {
                coursName: {required: "课程名不能为空", remote: jQuery.format("课程名已存在")},
                phone: {
                    required: "请输入手机号",
                    isMobile: "请正确填写手机号码"
                }
            }
        });

        $("#go_back_btn").on("click", function () {
            goBack();
        });
    });

    function goBack() {
        document.location.href = "${GLOBAL.basePath}/course/list";
    }

    function myCourse() {
        var exp = $("#exp").val();
        var phone = $("#phone").val();

        $.ajax({
            type: "POST",
            url: "queryUser",
            data: {
                phone: $("#phone").val()
            },
            dataType: "json",
            success: function (data) {
                if (data == '200') {
                    document.location.href = "${GLOBAL.basePath}/Emily/myCourse?courseId=''&exp=" + exp + "&phone=" + phone;
                } else {
                    layer.alert("请先提交信息");
                }
            },
            error: function () {
                layer.alert("请先提交信息");
            }
        })

    }
</script>